<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $product = \App\Models\Product::factory(10)->create();

        // images
        foreach ($product as $key => $value) {
            $product_id = $value['id'];

            \App\Models\Image::factory(1)->create(['product_id'=>$product_id]);

            //产品规格表 存product_id和price,stock,on_sale,name
            \App\Models\ProductSku::factory(1)->create(['product_id'=>$product_id]);
        }

        $attributes = \App\Models\Attribute::factory(10)->create();
        foreach ($attributes as $key => $value) {
            $attribute_id = $value['id'];
            \App\Models\Value::factory(1)->create(['attribute_id'=>$attribute_id]);    
        }

        $product_sku_data =  \App\Models\ProductSku::get();
        $attributes_data = \App\Models\Attribute::get();
        foreach ($product_sku_data as $key => $value) {
            $product_sku_id = $value['id'];
            $attribute_id = $attributes_data[$key]['id'];
            \App\Models\ProductSkuAttribute::create(['attribute_id'=>$attribute_id,'product_sku_id'=>$product_sku_id]);
        }       


    }
}
